import matplotlib.pyplot as plt
import pandas as pd

# 手动定义的列名，根据您的CSV文件实际的列结构进行调整
column_names = [
    'Unit CLAP/day [$]', 'Unit PLAC/day [$]', 'Aver. TAC of base schedule [$]',
    '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18',
    'Reduced TAC [$]', 'CLAP [$]', 'CLDP [$]', 'PLAC [$]', 'Sum of suggested postponement [day]',
    'Ratio of unit CLAP to unit PLAC'
]

# 读取CSV文件，使用上面定义的列名
df = pd.read_csv('../test/sensitivity_table-副本.csv', header=None, names=column_names)

# 选择1列和2列作为x和y轴的自变量
x = df[column_names[0]]  # Unit CLAP/day [$]
y = df[column_names[1]]  # Unit PLAC/day [$]

# 选择3列、22列、26列和27列作为因变量
z1 = df[column_names[2]]  # Aver. TAC of base schedule [$]
z2 = df[column_names[21]]  # Reduced TAC [$]
z3 = df[column_names[25]]  # PLAC [$]
z4 = df[column_names[26]]  # Ratio of unit CLAP to unit PLAC

# 创建一个包含3行4列的子图的图形窗口
fig, axs = plt.subplots(3, 4, figsize=(20, 15))

# 绘制12个子图
for i, x_value in enumerate(x.unique()):
    row = i // 4
    col = i % 4

    # 绘制y和四个因变量的关系
    axs[row, col].plot(y, z1.iloc[i], marker='o', label='Reduced TAC [$]')
    axs[row, col].plot(y, z2.iloc[i], marker='x', label='CLAP [$]')
    axs[row, col].plot(y, z3.iloc[i], marker='*', label='PLAC [$]')
    axs[row, col].plot(y, z4.iloc[i], marker='s', label='Ratio')

    axs[row, col].set_title(f'Unit CLAP/day [$] = {x_value}')
    axs[row, col].set_xlabel('Unit PLAC/day [$]')
    axs[row, col].set_ylabel('Values')
    axs[row, col].legend()

# 调整子图间距
plt.tight_layout()

# 保存图形
plt.savefig('12_subplots.png')

# 显示图形
plt.show()